export default {
  // 时间格式: YYYY年MM月DD日
  getFormatDate (date) {
    let y = date.getFullYear()
    var m = date.getMonth() + 1
    m = m < 10 ? '0' + m : m
    var d = date.getDate()
    d = d < 10 ? '0' + d : d
    return y + '-' + m + '-' + d
  },
  // 时间格式: YYYY年MM月DD日 时:分:秒
  getDetailedFormatDate (date) {
    let y = date.getFullYear()
    var m = date.getMonth() + 1
    m = m < 10 ? '0' + m : m
    var d = date.getDate()
    d = d < 10 ? '0' + d : d
    var h = date.getHours()
    h = h < 10 ? '0' + h : h
    var minute = date.getMinutes()
    minute = minute < 10 ? '0' + minute : minute
    var second = date.getSeconds()
    second = second < 10 ? '0' + second : second
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
  },
  // 时间格式:yyyyMMddHHmmss
  getDateTimeToString (date_) {
    var year = date_.getFullYear()
    var month = date_.getMonth() + 1
    var day = date_.getDate()
    if (month < 10) month = '0' + month
    if (day < 10) day = '0' + day

    var hours = date_.getHours()
    var mins = date_.getMinutes()
    var secs = date_.getSeconds()
    var msecs = date_.getMilliseconds()
    if (hours < 10) hours = '0' + hours
    if (mins < 10) mins = '0' + mins
    if (secs < 10) secs = '0' + secs
    if (msecs < 10) secs = '0' + msecs
    return '' + year + month + day + hours + mins
  },
  // 获取当前月份的第一天
  getCurrentMonthFirst () {
    var date = new Date()
    date.setDate(1)
    var month = parseInt(date.getMonth() + 1)
    var day = date.getDate()
    if (month < 10) {
      month = '0' + month
    }
    if (day < 10) {
      day = '0' + day
    }
    return date.getFullYear() + '-' + month + '-' + day
  },
  // 获取当前月份的最后一天
  getCurrentMonthLast () {
    var date = new Date()
    var currentMonth = date.getMonth()
    var nextMonth = ++currentMonth
    var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1)
    var oneDay = 1000 * 60 * 60 * 24
    var lastTime = new Date(nextMonthFirstDay - oneDay)
    var month = parseInt(lastTime.getMonth() + 1)
    var day = lastTime.getDate()
    if (month < 10) {
      month = '0' + month
    }
    if (day < 10) {
      day = '0' + day
    }
    return date.getFullYear() + '-' + month + '-' + day
  },
  // 获取当天日期
  getNowFormatDate () {
    var date = new Date()
    var seperator1 = '-'
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var strDate = date.getDate()
    if (month >= 1 && month <= 9) {
      month = '0' + month
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = '0' + strDate
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate
    return currentdate
  }
}
